<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
setlocale(LC_ALL, 'en_US.utf8');
error_reporting(E_ALL & ~E_NOTICE);

set_include_path(get_include_path() . PATH_SEPARATOR . 'lib');

// fetch the server name used for this request
$serverName = $_SERVER['SERVER_NAME'];

// filter the server name
$serverName = strtolower($serverName);
$serverName = str_replace('/', '', $serverName);
$serverName = str_replace('\\', '', $serverName);

$defaultVirtualHostConfigFile = 'config/virtualhosts/default.inc.php';
$virtualHostConfigFile = 'config/virtualhosts/' . $serverName . '.inc.php';

$escape_config = array();
$escape_config['virtualhost'] = $serverName;

// load the default settings
require_once('config/defaults.inc.php');

// try to load a configuration file
if(file_exists($virtualHostConfigFile))
{
	require_once($virtualHostConfigFile);
}
else if(file_exists($defaultVirtualHostConfigFile))
{
	require_once($defaultVirtualHostConfigFile);
	$escape_config['virtualhost'] = 'default';
}
else
{
	header("HTTP/1.1 404 Not Found");
	header("Status: 404 Not Found");
	header('Content-Type: text/plain');
	print 'Error: virtualhost ' . $serverName . ' is not configured';
	die();
}

// perform post config load checks
require_once('config/check.inc.php');
